
package token.basic;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.e885.log.E885Logger;
import com.e885.util.web.CommandToken;
import common.CommonHttpServlet;

/**
 * 驗證 token
 * 
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2001-2008
 */

public class BasicTokenDoAddServlet extends CommonHttpServlet
{
	private static final long serialVersionUID = 8658410885761272629L;

	private static int count = 1;

	private static int validCount = 1;

	private static int invalidCount = 1;

	protected void service( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
	{
		String requestToken = request.getParameter( CommandToken.TOKEN );
		String sessionToken = (String)request.getSession( true ).getAttribute( CommandToken.TOKEN );
		
		PrintWriter writer = response.getWriter();
		
		E885Logger.testLog.debug( "count:" + count++ );

		if( CommandToken.isValid( request ) )
		{
			E885Logger.testLog.debug( "validCount:" + validCount++ );

			CommandToken.set( request );
			
			writer.write( "token is valid" );
		}
		else
		{
			E885Logger.testLog.debug( "invalidCount:" + invalidCount++ );
			
			writer.write( "token is invalid" );
		}
		writer.write( "<br>" );
		writer.write( "<br>" );
		writer.write( "requestToken:" + requestToken );
		writer.write( "<br>" );
		writer.write( "sessionToken:" + sessionToken );
	}
}
